#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e5 + 5;

int n, m;
struct Seg {
  int l, r, d;
  bool operator<(const Seg& b) const { return d < b.d; }
} a[N];
int x[N << 1], num;

int mx[N << 3], tag[N << 3];
void addtag(int d, int p) {
  tag[p] += d;
  mx[p] += d;
}
void pushup(int p) { mx[p] = tag[p] + max(mx[p << 1], mx[p << 1 | 1]); }
void update(int L, int R, int d, int p, int l, int r) {
  if (L <= l && R >= r) {
    addtag(d, p);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, d, p << 1, l, mid);
  if (R > mid) update(L, R, d, p << 1 | 1, mid + 1, r);
  pushup(p);
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) {
    cin >> a[i].l >> a[i].r;
    a[i].d = a[i].r - a[i].l;
    x[i] = a[i].l;
    x[i + n] = a[i].r;
  }
  sort(a + 1, a + n + 1);
  sort(x + 1, x + n * 2 + 1);
  num = unique(x + 1, x + n * 2 + 1) - x - 1;
  rep(i, 1, n) {
    a[i].l = lower_bound(x + 1, x + num + 1, a[i].l) - x;
    a[i].r = lower_bound(x + 1, x + num + 1, a[i].r) - x;
  }
  //
  int ans = 1e9;
  int h = 1, t = 0;
  while (++t <= n) {
    update(a[t].l, a[t].r, 1, 1, 1, num);
    while (h <= t && mx[1] >= m) {
      ans = min(ans, a[t].d - a[h].d);
      update(a[h].l, a[h].r, -1, 1, 1, num);
      h++;
    }
  }
  if (ans == 1e9) ans = -1;
  cout << ans;
  return 0;
}